<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
		<script type="text/javascript" src="../../Vue.js/js/vue.min.js" charset="UTF-8"></script>
		<script type="text/javascript" src="../../js/unit/ProcessTiming.js" charset="UTF-8"></script>
	</head>
	<body>
		<h3>字符串数据格式转换</h3>
		<ul>
			<li>
				<p></p>
				<span>测试结果：</span>
			</li>
		</ul>
	</body>
	<script type="text/javascript">
			
		var transformFormat = function(strNum,format){
			if(typeof strNum == "number"){
				strNum = strNum.toString();
			}
			if(format == "#,###"){
				
				if(strNum.indexOf(".")>=0){
					var strLength = strNum.length;
					var strHead = strNum.substring(0,strNum.indexOf("."));
					var strFoot = strNum.substring(strNum.indexOf("."),strLength);
				}else{
					var strHead = strNum;
					var strFoot = "";
				}
				var str = "";
				//方法一	(经测试显示，方法一的用时更短)
				timeGet.getNowTime("转换开始:");
			for(var n = 0;n<10000;n++){
				var HeadArr = strHead.split("");
				var result = [];
				
				
				for(var i = (strHead.length-1),m = 0;i>=0;i--,m++){
					result.push(HeadArr[i]);
					if(m%3==2&&i!=0){
						result.push(",");
					}
				}
				result.reverse();
				for(var index in result){
					str += result[index];
				}
			}	
				
				
				//方法二
				/* var headLength = strHead.length;
				var remainder = headLength%3;
				if(remainder==0){
					remainder = 2;
				}else if(remainder==1){
					remainder = 0;
				}else if(remainder==2){
					remainder = 1;
				}
				for(var index in strHead){
					str += strHead.charAt(index);
					if(index%3==remainder&&index!=(headLength-1)){
						str += ",";
					}
				}
			} */
			}
			timeGet.getNowTime("转换结束:");
			return str + strFoot;
		}
		
		var resuletNum = transformFormat("111678890112.00","#,###");
		// console.log(resuletNum);
	</script>
</html>